package com.baizhi.shane.sys.controller;

import com.baizhi.shane.common.base.Result;
import com.baizhi.shane.constant.ApiMapping;
import com.baizhi.shane.constant.TableNameMapping;
import com.baizhi.shane.sys.entity.SysDictKey;
import com.baizhi.shane.sys.entity.SysDictValue;
import com.baizhi.shane.sys.service.SysDictKeyService;
import com.baizhi.shane.sys.vo.InsertOneKeyInVO;
import com.baizhi.shane.sys.vo.PageKeyInVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 闻柏智
 * @date 2023/04/30 14:14:30
 */
@RestController
@RequestMapping(TableNameMapping.SYS_DICT_KEY)
@Api(tags="字典Key表")
public class SysDictKeyController {

    @Resource
    SysDictKeyService sysDictKeyService;

    /**
     * 插入一条数据字典的KEY
     *
     * @Author 闻柏智
     * @Date 14:31 2023/4/30
     * @Param insertOneKeyInVO
     * @return com.baizhi.baiweiexam.common.base.Result<java.lang.String>
     **/
    @ApiOperation(value="增加字典Key", notes="增加字典Key")
    @PostMapping(value = ApiMapping.INSETR_ONE_KEY)
    public Result<String> insertOneKey(
            @RequestBody InsertOneKeyInVO insertOneKeyInVO
    ) {
        String successString = sysDictKeyService.insertOneKey(insertOneKeyInVO);
        return Result.OK(successString);
    }

    /**
     * 分页查询所有字典Key
     *
     * @Author 闻柏智
     * @Date 19:48 2023/4/30
     * @Param pageKeyInVO
     * @return com.baizhi.baiweiexam.common.base.Result<com.baomidou.mybatisplus.core.metadata.IPage<com.baizhi.baiweiexam.sys.entity.SysDictKey>>
     **/
    @ApiOperation(value="分页查询所有字典Key", notes="分页查询所有字典Key")
    @PostMapping(value = ApiMapping.PAGE_KEY)
    public Result<IPage<SysDictKey>> pageKey(
            @RequestBody PageKeyInVO pageKeyInVO
    ) {

        Page<SysDictKey> dictKeyPage = sysDictKeyService.pageKey(pageKeyInVO);
        return Result.OK(dictKeyPage);
    }

    @ApiOperation(value="插入一个字典Value", notes="插入一个字典Value")
    @PostMapping(value = ApiMapping.INSERT_ONE_VALUE)
    public Result<String> insertOneValue(
            @RequestBody SysDictValue sysDictValue
            ) {

        String successString = sysDictKeyService.insertOneValue(sysDictValue);
        return Result.OK(successString);
    }

}
